/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package multiTabs;
import core.DirChangeListener;
import core.IView;
import core.TreeDirSelectionListener;
import drapdrop.MyTransferHandler;
import gui.mainFrame;
import java.awt.Component;
import java.awt.event.MouseListener;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.TreeSelectionListener;
import view.MyFocusListener;
/**
 *
 * @author Alex
 */
public class MultiTabs extends javax.swing.JPanel {

    public TreeDirSelectionListener getTreeDirSelectionListener()
    {
        return _treeDirSelectionListener;
    }


     public void doViewDetail()
     {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            ((Tab)com).doViewDetail();
        }
     }

     public void doViewThumbnail()
     {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            ((Tab)com).doViewThumbnail();
        }
     }
     
     

    private mainFrame _mainFrame;
    private MyFocusListener _myFocusListenerLeft;
    private MyFocusListener _myFocusListenerRight;
    private MyTransferHandler _transferHandler;
    private DirChangeListener _dirChangeListener;
    private TreeDirSelectionListener _treeDirSelectionListener;
    /**
     * Creates new form MultiTabs
     */
    public MultiTabs() {
        initComponents();
        
        //ngdlong - Load res
        loadResource();
    }
    
    public MultiTabs(mainFrame mainFrame)
    {
        initComponents();
        _mainFrame = mainFrame;
        loadResource();
    }
    
    public void doViewBrief() {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab) {
            ((Tab) com).doViewBrief();
        }
    }
    
    public void doRereadSource()
    {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            ((Tab)com).getViewLeft().refresh();
            ((Tab)com).getViewRight().refresh();
        }        
    }
    
    void loadResource()
    {
        // Create single tab
        Tab tab = new Tab(this);
        tabPanel.addTab(tab.getViewActive().getPathCurrentDir(), tab);
        tabPanel.setSelectedIndex(tabPanel.getTabCount()-1);
        
    }

    
    public IView getViewLeft()
    {
        Component com = tabPanel.getSelectedComponent();
        if(com instanceof Tab)
        {
            return ((Tab)com).getViewLeft();
        }
        return null;
    }
    
    public IView getViewRight()
    {
        Component com = tabPanel.getSelectedComponent();
        if(com instanceof Tab)
        {
            return ((Tab)com).getViewRight();
        }
        return null;
    }
    
    public JScrollPane getLeftScrollPane()
    {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            return ((Tab)com).getLeftScrollPane();
        }
        return null;
    }

    public JScrollPane getRightScrollPane()
    {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            return ((Tab)com).getRightScrollPane();
        }
        return null;
    }
    
    public IView getViewActive()
    {
        Component com = tabPanel.getSelectedComponent();
        if(com instanceof Tab)
        {
            return ((Tab)com).getViewActive();
        }
        return null;
    }
    
    public byte getActiveView()
    {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            return ((Tab)com).getActiveView();
        }
        return 0;
    }
    
    public JScrollPane getScrollPaneActive()
    {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            return ((Tab)com).getScrollPaneActive();
        }
        return null;
    }
    
    public mainFrame getFormMain()
     {
        return _mainFrame;
     }

     public JTabbedPane getTabPane()
     {
        return tabPanel;
     }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabPanel = new javax.swing.JTabbedPane();

        tabPanel.setName("tabPanel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane tabPanel;
    // End of variables declaration//GEN-END:variables

    public MyFocusListener getMyFocusListenerActive()
    {
        if (getViewLeft().isFocus())
        {
            return _myFocusListenerLeft;
        }
        return _myFocusListenerRight;
    }
    
    public DirChangeListener getDirChangeListener()
    {
        return _dirChangeListener;
    }

     public void showTree(byte TREE_TYPE_BOTH)
     {
        Component com = tabPanel.getSelectedComponent();
        if (com instanceof Tab)
        {
            ((Tab)com).showTree(TREE_TYPE_BOTH);
        }
      }
}
